<template>
<div class="pt30">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <el-form-item :label="$t('setting.get_phone_number')">
        <el-checkbox-group v-model="form.checkedCities">
          <el-checkbox
            v-for="(item, index) in allType"
            :label="item.value"
            :key="index"
            >{{item.text}}</el-checkbox
          >
        </el-checkbox-group>
      </el-form-item>

      <el-form-item :label="$t('setting.after_rejection')" prop="sendDay">
        <div style="width: 500px">
          <el-input :placeholder="$t('setting.please_input')" v-model="form.sendDay" type="number">
            <template #append> {{$t('setting.days_no_remind')}} </template>
          </el-input>
          <p class="gray">{{$t('setting.rejection_delay_tip')}}</p>
        </div>
      </el-form-item>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button
          size="small"
          type="primary"
          @click="onSubmit"
          :loading="loading"
          >{{$t('setting.submit_button')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from "@/api/setting.js";
export default {
  data() {
    return {
      /*是否正在加载*/
      loading: false,
      /*订单*/
      form: {
        checkedCities: [],
        sendDay: 7
      },
      allType: []
    };
  },
  created() {
    this.getParams();
  },
  methods: {
    /*获取配置数据*/
    getParams() {
      let self = this;
      SettingApi.getPhoneDetail({}, true).then(res => {
        let vars = res.data;
        self.form.checkedCities = vars.checkedCities;
        self.form.sendDay = vars.sendDay;
        self.allType = vars.allType;
        self.loading = false;
      }).catch(error => {});
    },
    /*提交*/
    onSubmit() {
      let self = this;
      let params = this.form;
      self.loading = true;
      SettingApi.editGetPhone(params, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("setting.setting_success"),
          type: "success"
        });
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

